package be.teletask.onvif.parsers;

import be.teletask.onvif.models.GetAudioOutputConfiguration;
import be.teletask.onvif.models.GetAudioOutputConfigurationOptions;
import be.teletask.onvif.responses.OnvifResponse;
import be.teletask.onvif.util.XmlToJsonUtils;
import com.alibaba.fastjson.JSONObject;

/**
 * Created by Tomas Verhelst on 04/09/2018.
 * Copyright (c) 2018 TELETASK BVBA. All rights reserved.
 */
public class GetAudioOutputConfigurationOptionsParser extends OnvifParser<GetAudioOutputConfigurationOptions> {

    //Constants
    public static final String TAG = GetAudioOutputConfigurationOptionsParser.class.getSimpleName();

    @Override
    public GetAudioOutputConfigurationOptions parse(OnvifResponse response) {
        JSONObject bodyObjet = XmlToJsonUtils.xmlToJson(response.getXml());
        GetAudioOutputConfigurationOptions audioOutputOptions = new GetAudioOutputConfigurationOptions();

        JSONObject profileObject = bodyObjet.getJSONObject("GetAudioOutputConfigurationOptionsResponse").getJSONObject("Options");

        String outputTokensAvailable = profileObject.getString("OutputTokensAvailable");
        String sendPrimacyOptions = profileObject.getString("SendPrimacyOptions");
        String outputLevelRange  = profileObject.getString("OutputLevelRange");

        audioOutputOptions.setOutputTokensAvailable(outputTokensAvailable);
        audioOutputOptions.setSendPrimacyOptions(sendPrimacyOptions);
        audioOutputOptions.setOutputLevelRange(outputLevelRange);

        return audioOutputOptions;
    }

}
